package com.eaoa.uc.busscore.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.eaoa.base.EABaseAction;
import com.eaoa.constants.PubPermissionConstants;
import com.eaoa.query.bus.BusScoreQuery;
import com.eaoa.uc.busscore.form.BusScoreCondition;
import com.eaoa.uc.busscore.form.BusScoreSearchForm;

public class BusScoreManageSearchAction extends EABaseAction{

	protected ActionForward doWork(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		BusScoreSearchForm sform = (BusScoreSearchForm) form;
		sform.initConditionPost();
		BusScoreCondition condition = (BusScoreCondition) sform.getCondition();
		
		BusScoreQuery query = new BusScoreQuery();
		if(hasPermission(request, PubPermissionConstants.BUSSCORE_QUERYCUSTOMERS)){
			query.setAccountno(getEmployee(request).getCustomerAccountids());
		}else{
			query.setAccountno(getEmployee(request).getAccountno());
		}
		
		query.setSource(condition.getSource());
		query.setUsername(condition.getUsername());
		//query.setCreatedate(condition.getCreatedatefrom(), condition.getCreatedateto());
		query.setPageRange(sform.getPageinfo());
		query.execute();
		
		request.setAttribute("results", query.getResults());
		
		return mapping.findForward("success");
	}
}
